import axios from "axios"
import store from '@/store'
import JSONbig from 'json-bigint'

const request = axios.create({
  baseURL: "http://ttapi.research.itcast.cn/",
  transformResponse: [function (data) {
    try {
      return JSONbig.parse(data)
    } catch (err) {
      return {
        data
      }
    }
  }]
})

request.interceptors.request.use(function (config) {
  if(store.state.user) {
    config.headers.Authorization = `Bearer ${store.state.user.token}`
  }

  return config
})


export default request
